<?php
require_once 'common.php';
require_once "Login.php";
require_once 'ResultData.php';
require_once 'config.php';

session_start();

if (isGet()) {
    echo "不得以GET访问";
    exit;
}

$name = $_SESSION['username'];
$psd = trim($_SESSION['password']);

if (!$name || !$psd) {
    $result->code = 404;
    $result->msg = "用户未登录,无法获取用户信息";
    exit(json_encode($result));
}


$result = new ResultData();


$login = new Login();
$result->data = $login;

$id = intval($id);

$con = mysqli_connect($servername, $username, $password, $database, $port);

if (!$con) {
    $result->code = 404;
    $result->msg = "数据库连接不上";
    exit(json_encode($result));
}

$sql = "SELECT id, name, password FROM t_login WHERE  name= '{$name}' AND password = '{$psd}'";

$record = $con->query($sql);

if ($record->num_rows > 0) {
    while ($row = $record->fetch_assoc()) {
        $login->id = $row["id"];
        $login->name = $row["name"];
        $login->password = $row["password"];
    }
}

mysqli_close($con);


exit(json_encode($result));
